package com.qf.controller;

import com.qf.pojo.User;
import com.qf.pojo.UserResp;
import com.qf.service.UserService;

import com.qf.utils.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RestController

public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping("/sendMail")
    @ResponseBody
    public String sendMail(@RequestBody HashMap mail, HttpServletRequest req) {
        String email= (String) mail.get("mail");
        return userService.sendMail(email, req);
    }
    @RequestMapping("/reg")
    public String registry(@RequestBody UserResp userResp, HttpServletRequest req) {
        String registry = userService.registry(userResp, req);
        if(registry.equals("success")){
            return "ok";
        }
        return "";
    }
    @RequestMapping("/login")
    public ResponseEntity login(@RequestBody User user,HttpSession session){
        User login = userService.login(user);
session.setAttribute(SYS.SYS_USER,login);
        if(login!=null){
            return ResponseEntity.ok("ok");
        }else{
            return ResponseEntity.ok("no");
        }
    }
}
